/**
 * 点击登录跳转页面
 */
 function land() {
         localStorage.removeItem('userlist')
         location.href="../pages/login.html"
}
const landBtn=document.querySelector('.onland')
function onLand(){
         let userListstr=localStorage.getItem('userlist')
         let userList=JSON.parse(userListstr)
         let str=` <img src="${userList.headerimg}" alt="用户登录" />
         <span>${userList.username}</span>`
         landBtn.innerHTML=str
}
/**
 * 搜索商品
 * 获取表单内容
 */
 const searchInput=document.querySelector('.search input')
 const searchbtnEle=document.querySelector('.search button')
 const productEle=document.querySelector('.product')
//  console.log(searchInput);
 function searchProduct(){
        searchbtnEle.addEventListener('click',function(){
                if (searchInput.value == "") {
                      alert('输入的内容不能为空') 
                      return  
                }
                document.documentElement.scrollTop=productEle.offsetTop
                axios({
                        method:'get',
                        url:'http://api.yuguoxy.com/api/shop/search',
                        params:{
                             keyword:searchInput.value,    
                        }
                     }).then(response=>{
                           let {resultCode,resultInfo}=response.data
                              if (resultCode==1) {
                                      let list =resultInfo.list
                                //       console.log(list);
                                      showProductList1(list)  
                              }
                     })
        })
         
 }
 function showProductList1(list){
     let str =list.map(item=>{
         return `
         <li onclick="productdetail(${item.id})">
         <img src="${item.picture}" alt="productimg">
         <p class="cart-introduce">${item.product}</p>
         <p class="cart-source"><span class="source">淘宝</span> <span>包邮</span> </p>
         
         <div class="cart">
           <p class="cart-price">
             <span>￥</span>
             <span class="price">${parseInt(item.price)}</span> 
             <span class="price-decimal">${((item.price).toString()).substring((item.price).toString().indexOf('.',1))}</span>
              <span>${item.oldprice}人已买</span>
              <span class="vol">3元卷</span>
           </p>
         </div>     
       </li>
             `
     }).join('')
     const  productListul=document.querySelector('.productlist ul')
     productListul.innerHTML=str
 }
function lookCart() {
       let userList=localStorage.getItem('userlist')
        if (userList==undefined) {
                alert('你还没有登录')
                return
                
        }else{
                location.href='../pages/shoppingcart.html'
        }
        
}
function index(){
        location.href='../pages/index.html'
        
}
function nine() {
        location.href='../pages/nine.html'
        
}
function isNull(){
         alert('对不起你没有选择商品')
}
searchProduct()
onLand()